package com.chujian.system.sys.controller;


import cn.hutool.core.collection.CollUtil;
import com.chujian.framework.core.base.BaseController;
import com.chujian.framework.core.base.BaseService;
import com.chujian.framework.core.tsdata.Result;
import com.chujian.sys.entity.SysRoleMenu;
import com.chujian.sys.vo.SaveRoleMenuVo;
import com.chujian.system.sys.service.SysRoleMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 角色功能表控制层
 *
 * @author chujian
 * @since 2021-08-03
 */
@RequestMapping("/sysRoleMenu")
@RestController
@Slf4j
public class SysRoleMenuController extends BaseController<SysRoleMenu> {

    @Resource
    private SysRoleMenuService baseService;

    @Override
    public BaseService<SysRoleMenu> getBaseService() {
        return baseService;
    }

    /**
     * 获取角色菜单列表
     *
     * @param roleId roleId
     * @return List<SysRoleMenu>
     */
    @GetMapping("/listRoleMenu")
    public Result<?> listRoleMenu(@RequestParam("roleId") Long roleId) {
        return okRs(baseService.listRoleMenu(CollUtil.newArrayList(roleId), true));
    }


    /**
     * 保存角色菜单
     *
     * @param roleMenuDto roleMenuDto
     * @return -
     */
    @PostMapping("/saveRoleMenu")
    public Result<?> saveRoleMenu(@RequestBody SaveRoleMenuVo roleMenuDto) {
        baseService.saveRoleMenu(roleMenuDto.getRoleId(), roleMenuDto.getMenuIds());
        return okRs();
    }


}
